package br.indt.framework.ui.common;


import com.nokia.mid.ui.frameanimator.FrameAnimator;
import com.nokia.mid.ui.frameanimator.FrameAnimatorListener;

public class CirclesFrameAnimatorListener implements FrameAnimatorListener {

    private Display gestureCanvas;
    private FrameAnimator frameAnimator;

    public CirclesFrameAnimatorListener(Display gestureCanvas) {
        this.gestureCanvas = gestureCanvas;
		frameAnimator = new FrameAnimator();
        frameAnimator.register(0,
                               0,
                               (short)100,
                               (short)150,
                               this);

    }

    public void animate(FrameAnimator frameAnimator,
                        int x,
                        int y,
                        short delta,
                        short deltaX,
                        short deltaY,
                        boolean lastFrame) {

    	if(y > gestureCanvas.getCurrentDisplayable().getMaxScrollY()) {
    		y = gestureCanvas.getCurrentDisplayable().getMaxScrollY();
    	}
    	
    	int minScrollY = (gestureCanvas.getContentHeight() <= gestureCanvas.getScrollableHeight()) ? Display.TITLE_BAR_HEIGHT : (gestureCanvas.getContentHeight() - gestureCanvas.getScrollableHeight() - Display.TITLE_BAR_HEIGHT) * -1;
    	if(y < minScrollY) y = minScrollY;
    	
    	
    	//added for resolve the problem of duplicate items in the screen OptionsMenuScreen
    	//Begin
    	try{
    	if(this.gestureCanvas.getCurrentDisplayable().getName() == "OptionMenu"){
//			int val = (Display.getInstance().getHeight()- Display.MENU_BAR_HEIGHT_TOUCH )-(OptionMenuScreenBase.gethItem()*this.gestureCanvas.getCurrentDisplayable().getItemCount());
//			this.gestureCanvas.getCurrentDisplayable().setCurrentY(val);
    		
    	}else if(this.gestureCanvas.getCurrentDisplayable().getName() == "OptionMenuFullTouch"){
    		
				this.gestureCanvas.getCurrentDisplayable().setCurrentY(30);
    	}else{
    		this.gestureCanvas.getCurrentDisplayable().setCurrentY(y);
    	}
    	
    	} catch (Exception e) {
		//	Utils.logError("CirclesFrameAnimatorListener:: animate : " + e);
		}
    	//End
    	
//        this.gestureCanvas.getCurrentDisplayable().setCurrentY(y);

        gestureCanvas.repaint();
        
        gestureCanvas.getCurrentDisplayable().setDragCounterY(0);

    }
    
    public FrameAnimator getFrameAnimator() {
		return frameAnimator;
	}

}
